Add Method (T, CancellationToken)

Task Parallel System.Threading

Adds the item to the BlockingCollection<(Of <(T>)>). A OperationCanceledException is thrown if the CancellationToken is canceled.

Namespace:  System.Collections.Concurrent
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Sub Add ( _
	item As T, _
	cancellationToken As CancellationToken _
)
C#
public void Add(
	T item,
	CancellationToken cancellationToken
)

Parameters

item
Type: T
The item to be added to the collection. The value can be a null reference.
cancellationToken
Type: System.Threading..::.CancellationToken
A cancellation token to observe.

Remarks

If a bounded capacity was specified when this instance of BlockingCollection<(Of <(T>)>) was initialized, a call to Add(T, CancellationToken) may block until space is available to store the provided item.

Exceptions

ExceptionCondition
System..::.OperationCanceledExceptionIf the CancellationToken is canceled.
System..::.InvalidOperationExceptionThe BlockingCollection<(Of <(T>)>) has been marked as complete with regards to additions.
System..::.ObjectDisposedExceptionThe BlockingCollection<(Of <(T>)>) has been disposed.
System..::.InvalidOperationExceptionThe underlying collection didn't accept the item.

See Also